/* m_heatGot, m_heatLoss, m_layNumber, m_matrixLeft, m_matrixRight
 * 
 */
package com.simulation;

import com.simulation.All.ModelType;

class TEquationsSolver
{
	double[][] m_matrixLeft;
	double[] m_matrixRight;

    TEquationsSolver(int nx, ModelType modelFlag) {
    	int len = 10;
    	if(modelFlag.compareTo(ModelType.GasEnergy)>=0)
    		len=2*nx;
    	if(modelFlag.compareTo(ModelType.AddLiquid)>=0)
    		len=3*nx;
    	if(modelFlag.compareTo(ModelType.AddPressure)>=0)
    		len=4*nx;
    	if(modelFlag.compareTo(ModelType.AddVirus)>=0)
    		len=5*nx;
    	if(modelFlag.compareTo(ModelType.AddNoLocal)>=0)
    		len=6*nx;

    	//m_matrixLeft.clear();
    	m_matrixLeft = new double[len][];
    	//m_matrixRight.clear();
    	m_matrixRight = new double[len];

    	for(int i=0;i<len;i++)
    	{
    		m_matrixRight[i] = 0.0f;
    		m_matrixLeft[i] = new double[len];
    		for(int j=0;j<len;j++)
    		{
    			m_matrixLeft[i][j] = 0.0; 
    		}
    	}
    };

    void EquationsMatrix(TNumericalFabric fabric, TNumericalGas gas,
                         TNumericalLiquidWater liquid,TNumericalVirus virus,
                         double stefanConstant,TNumericalSelfHeating selfHeat
                         )
    {
    	for(int i=1;i<fabric.m_nx-1;i++)
        {
            /* Ca*/
            m_matrixLeft[i][i-1]= fabric.m_mu*(fabric.m_coeWaterVapor[i]+fabric.m_coeWaterVapor[i-1])/2;

            m_matrixLeft[i][i]= -fabric.m_vGas[i].preNodeValue
                                -fabric.m_mu*(fabric.m_coeWaterVapor[i]+fabric.m_coeWaterVapor[i-1])/2
                                -fabric.m_mu*(fabric.m_coeWaterVapor[i]+fabric.m_coeWaterVapor[i+1])/2;
            m_matrixLeft[i][i+1]=fabric.m_mu/*fabric.m_tortuosityWaterVapor*/*(fabric.m_coeWaterVapor[i]+fabric.m_coeWaterVapor[i+1])/2;
            m_matrixRight[i]=-fabric.m_cWaterVapor[i].preNodeValue * fabric.m_vGas[i].preNodeValue
                             + fabric.m_waterVaporItem[i]*fabric.m_deltaT;
            
            /* Tf */
            m_matrixLeft[fabric.m_nx+i][fabric.m_nx+i-1]= fabric.m_mu*(fabric.m_thermoConductivity[i]
                                                            + fabric.m_thermoConductivity[i-1])/2;

            m_matrixLeft[fabric.m_nx+i][fabric.m_nx+i]= -fabric.m_volumetricHeatCapacity[i]
                                                          - fabric.m_mu*(fabric.m_thermoConductivity[i]+ fabric.m_thermoConductivity[i-1])/2
                                                          - fabric.m_mu*(fabric.m_thermoConductivity[i]+ fabric.m_thermoConductivity[i+1])/2;
            
            m_matrixLeft[fabric.m_nx+i][fabric.m_nx+i+1]= fabric.m_mu*(fabric.m_thermoConductivity[i]+ fabric.m_thermoConductivity[i+1])/2;
            m_matrixRight[fabric.m_nx+i]=-fabric.m_volumetricHeatCapacity[i] *fabric.m_tFabric[i].preNodeValue - fabric.m_temperatureItem[i]*fabric.m_deltaT;

            if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
            {
                m_matrixLeft[2*fabric.m_nx+i][2*fabric.m_nx+i-1]=fabric.m_mu*(fabric.m_diffusionCoeLiqWater[i]
                                                                       +fabric.m_diffusionCoeLiqWater[i-1])/2;

                m_matrixLeft[2*fabric.m_nx+i][2*fabric.m_nx+i]=-liquid.m_density
                                                                 -fabric.m_mu*(fabric.m_diffusionCoeLiqWater[i]+fabric.m_diffusionCoeLiqWater[i-1])/2
                                                                 -fabric.m_mu*(fabric.m_diffusionCoeLiqWater[i]+fabric.m_diffusionCoeLiqWater[i+1])/2;
                m_matrixLeft[2*fabric.m_nx+i][2*fabric.m_nx+i+1]=fabric.m_mu/*fabric.m_tortuosityLiqWater*/*(fabric.m_diffusionCoeLiqWater[i]+fabric.m_diffusionCoeLiqWater[i+1])/2;

                m_matrixRight[2*fabric.m_nx+i]=-liquid.m_density*fabric.m_vLiquidWater[i].preNodeValue +fabric.m_liquidWaterItem[i]*fabric.m_deltaT;

                /* first equations*/
                m_matrixLeft[i][2*fabric.m_nx+i]=fabric.m_cWaterVapor[i].preNodeValue ;

                m_matrixRight[i] +=fabric.m_cWaterVapor[i].preNodeValue * fabric.m_vLiquidWater[i].preNodeValue ;

            }
            if(fabric.m_modelFlag.compareTo(ModelType.AddPressure)>=0)
            {
                /* Ps*/
                m_matrixLeft[3*fabric.m_nx+i][3*fabric.m_nx+i-1]=fabric.m_mu*(fabric.m_coePressureGas[i]+fabric.m_coePressureGas[i-1])/2;
                m_matrixLeft[3*fabric.m_nx+i][3*fabric.m_nx+i]=-fabric.m_coePressureTime[i]
                                                                 -fabric.m_mu*(fabric.m_coePressureGas[i]+fabric.m_coePressureGas[i-1])/2
                                                                 -fabric.m_mu*(fabric.m_coePressureGas[i]+fabric.m_coePressureGas[i+1])/2;
                m_matrixLeft[3*fabric.m_nx+i][3*fabric.m_nx+i+1]=fabric.m_mu*(fabric.m_coePressureGas[i]+fabric.m_coePressureGas[i+1])/2;

                /* Tf*/
                m_matrixLeft[3*fabric.m_nx+i][fabric.m_nx+i]=-fabric.m_coePressureTempetratureToTime[i];

                /* varelopsin(l)*/
                m_matrixLeft[3*fabric.m_nx+i][2*fabric.m_nx+i]=-fabric.m_coePressureLiquidWaterTotime[i];

                m_matrixRight[3*fabric.m_nx+i]=-fabric.m_coePressureTime[i]*fabric.m_pressureGas[i].preNodeValue
                                                -fabric.m_coePressureTempetratureToTime[i]*fabric.m_tFabric[i].preNodeValue
                                                -fabric.m_coePressureLiquidWaterTotime[i]*fabric.m_vLiquidWater[i].preNodeValue
                                                +fabric.m_absorbedWaterVapor[i]*fabric.m_deltaT
                                                -fabric.m_volumeEvapCondensation[i]*fabric.m_deltaT;
                /* first equation*/
                m_matrixLeft[i][3*fabric.m_nx+i-1]=fabric.m_mu*(fabric.m_coePressureWaterVapor[i]+fabric.m_coePressureWaterVapor[i-1])/2;
                m_matrixLeft[i][3*fabric.m_nx+i]=-fabric.m_mu*(fabric.m_coePressureWaterVapor[i]+fabric.m_coePressureWaterVapor[i-1])/2
                                                  -fabric.m_mu*(fabric.m_coePressureWaterVapor[i]+fabric.m_coePressureWaterVapor[i+1])/2;
                m_matrixLeft[i][3*fabric.m_nx+i+1]=fabric.m_mu*(fabric.m_coePressureWaterVapor[i]+fabric.m_coePressureWaterVapor[i+1])/2;

                /* third equation*/
                m_matrixLeft[2*fabric.m_nx+i][3*fabric.m_nx+i-1]=fabric.m_mu*(fabric.m_coePressureLiquidWater[i]+fabric.m_coePressureLiquidWater[i-1])/2;
                m_matrixLeft[2*fabric.m_nx+i][3*fabric.m_nx+i]=-fabric.m_mu*(fabric.m_coePressureLiquidWater[i]+fabric.m_coePressureLiquidWater[i-1])/2
                                                                 -fabric.m_mu*(fabric.m_coePressureLiquidWater[i]+fabric.m_coePressureLiquidWater[i+1])/2;

                m_matrixLeft[2*fabric.m_nx+i][3*fabric.m_nx+i+1]= fabric.m_mu*(fabric.m_coePressureLiquidWater[i]+fabric.m_coePressureLiquidWater[i+1])/2;

            }

            if(fabric.m_modelFlag.compareTo(ModelType.AddVirus)>=0)
            {
                m_matrixLeft[4*fabric.m_nx+i][4*fabric.m_nx+i-1]=fabric.m_mu*(fabric.m_coeDiffusionVirus[i]+fabric.m_coeDiffusionVirus[i-1])/2;
                m_matrixLeft[4*fabric.m_nx+i][4*fabric.m_nx+i]=-fabric.m_vLiquidWater[i].preNodeValue
                                                                 -fabric.m_mu*(fabric.m_coeDiffusionVirus[i]+fabric.m_coeDiffusionVirus[i-1])/2
                                                                 -fabric.m_mu*(fabric.m_coeDiffusionVirus[i]+fabric.m_coeDiffusionVirus[i+1])/2;
                m_matrixLeft[4*fabric.m_nx+i][4*fabric.m_nx+i+1]=fabric.m_mu*(fabric.m_coeDiffusionVirus[i]+fabric.m_coeDiffusionVirus[i+1])/2;

                m_matrixLeft[4*fabric.m_nx+i][2*fabric.m_nx+i-1]=fabric.m_mu*(fabric.m_coeVirusToLiqWater[i]+fabric.m_coeVirusToLiqWater[i-1])/2;
                m_matrixLeft[4*fabric.m_nx+i][2*fabric.m_nx+i]=-fabric.m_cVirusInLiqWater[i].preNodeValue
                                                                 -fabric.m_mu*(fabric.m_coeVirusToLiqWater[i]+fabric.m_coeVirusToLiqWater[i-1])/2
                                                                 -fabric.m_mu*(fabric.m_coeVirusToLiqWater[i]+fabric.m_coeVirusToLiqWater[i+1])/2;
                m_matrixLeft[4*fabric.m_nx+i][2*fabric.m_nx+i+1]=fabric.m_mu*(fabric.m_coeVirusToLiqWater[i]+fabric.m_coeVirusToLiqWater[i+1])/2;

                m_matrixLeft[4*fabric.m_nx+i][3*fabric.m_nx+i-1]=fabric.m_mu*(fabric.m_coeVirusToPressure[i]+ fabric.m_coeVirusToPressure[i-1])/2;

                m_matrixLeft[4*fabric.m_nx+i][3*fabric.m_nx+i]= -fabric.m_mu*(fabric.m_coeVirusToPressure[i]+ fabric.m_coeVirusToPressure[i-1])/2
                                                                  -fabric.m_mu*(fabric.m_coeVirusToPressure[i]+ fabric.m_coeVirusToPressure[i+1])/2;
                m_matrixLeft[4*fabric.m_nx+i][3*fabric.m_nx+i+1]=fabric.m_mu*(fabric.m_coeVirusToPressure[i]+ fabric.m_coeVirusToPressure[i+1])/2;

                m_matrixRight[4*fabric.m_nx+i]=-2*fabric.m_vLiquidWater[i].preNodeValue * fabric.m_cVirusInLiqWater[i].preNodeValue
                                                +fabric.m_differentialVirus[i]*fabric.m_deltaT;
                m_matrixRight[i]= m_matrixRight[i]-fabric.m_cWaterVapor[i].preNodeValue * fabric.m_differentialVirus[i]/virus.m_density * fabric.m_deltaT;

                m_matrixRight[3*fabric.m_nx+i]= m_matrixRight[3*fabric.m_nx+i]+ fabric.m_coePressureLiquidWaterTotime[i]* fabric.m_differentialVirus[i]/virus.m_density*fabric.m_deltaT;

            }
            if(fabric.m_modelFlag.compareTo(ModelType.AddNoLocal)>=0)
            {
                m_matrixLeft[5*fabric.m_nx+i][5*fabric.m_nx+i-1]= fabric.m_coeDDwTg[i]*fabric.m_coeAfwTg[i]+fabric.m_coeFwTg[i];
                m_matrixLeft[5*fabric.m_nx+i][5*fabric.m_nx+i]= -(fabric.m_coeDDwTg[i]*fabric.m_coeAfwTg[i]+fabric.m_coeFwTg[i])
                                                                  -(fabric.m_coeDDeTg[i]*fabric.m_coeAfeTg[i]+fabric.m_coeFeTg[i])
                                                                  - fabric.m_coeLocalEquiGas[i]*fabric.m_deltaX/fabric.m_deltaT;
                                                                  //+ fabric.m_coeFweTg[i]; revise
                m_matrixLeft[5*fabric.m_nx+i][5*fabric.m_nx+i+1]= fabric.m_coeDDeTg[i]*fabric.m_coeAfeTg[i]+fabric.m_coeFeTg[i];
                m_matrixRight[5*fabric.m_nx+i]= -fabric.m_valueLocalEquiGas[i]*fabric.m_deltaX
                                                 -fabric.m_coeLocalEquiGas[i]*fabric.m_tGas[i].preNodeValue*fabric.m_deltaX/fabric.m_deltaT;
                m_matrixRight[fabric.m_nx+i]= m_matrixRight[fabric.m_nx+i]+ fabric.m_valueLocalEquiGas[i]*fabric.m_deltaT;

            }

            if(fabric.m_sourceItem.PCM)
            {
                m_matrixRight[fabric.m_nx+i]= m_matrixRight[fabric.m_nx+i]+ fabric.m_heatLossPCM[i]*fabric.m_deltaT;

            }
            if(fabric.m_sourceItem.Radiation)
            {
                m_matrixRight[fabric.m_nx+i]= m_matrixRight[fabric.m_nx+i]+ 2*fabric.m_sorptionConstant*stefanConstant
                                               *(Math.pow(fabric.m_tFabric[i].preNodeValue,4)-Math.pow((fabric.m_tFabric[0].preNodeValue+fabric.m_tFabric[fabric.m_nx-1].preNodeValue)/2,4))
                                               *fabric.m_deltaT; // revise1

            }
   		 	fabric.m_sourceItem.SelfHeating = false;
            if(fabric.m_sourceItem.SelfHeating)
            {
                selfHeat.SelfHeating(fabric.m_tFabric[i].preNodeValue);
                if(selfHeat.m_heatGot!=0)
                {
                     m_matrixRight[fabric.m_nx+i] -= selfHeat.m_heatGot *fabric.m_deltaT;
                }
                if(selfHeat.m_heatLoss!=0)
                {
                     m_matrixRight[fabric.m_nx+i] += selfHeat.m_heatLoss *fabric.m_deltaT;
                }
            }
        }// end for i
    };

    void GetMatrixBoundary(TNumericalFabric fabric,TNumericalGas gas ,
                           TNumericalLiquidWater liquid,TNumericalVirus virus,
                           double eSkin,boolean bodymodel,TNumericalSelfHeating selfHeat)
    {
    	/* Ca */
        if(!fabric.m_inContact)
        {
             m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0
                               - fabric.m_coeConvecMassIn* fabric.m_deltaX*fabric.m_vGas[0].preNodeValue/fabric.m_porosity;

             m_matrixLeft[0][1]=(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;
             m_matrixRight[0]= -fabric.m_coeConvecMassIn*fabric.m_vGas[0].preNodeValue*fabric.m_deltaX*fabric.m_CVaporInner/fabric.m_porosity;

        }
        else
        {
             m_matrixLeft[0][0] = 1.0;
             m_matrixRight[0] = fabric.m_CVaporInner;

        }

        if(!fabric.m_outContact)
        {
             m_matrixLeft[fabric.m_nx-1][fabric.m_nx-1]=fabric.m_coeConvecMassOut*fabric.m_vGas[fabric.m_nx-1].preNodeValue
                                                         *fabric.m_deltaX/fabric.m_porosity
                                                         +(fabric.m_coeWaterVapor[fabric.m_nx-1]+fabric.m_coeWaterVapor[fabric.m_nx-2])/2.0;

             m_matrixLeft[fabric.m_nx-1][fabric.m_nx-2]= -(fabric.m_coeWaterVapor[fabric.m_nx-1]+fabric.m_coeWaterVapor[fabric.m_nx-2])/2.0;

             m_matrixRight[fabric.m_nx-1]=fabric.m_coeConvecMassOut*fabric.m_deltaX *fabric.m_vGas[fabric.m_nx-1].preNodeValue
                                          *fabric.m_CVaporOuter/fabric.m_porosity;

        }
        else
        {
             m_matrixLeft[fabric.m_nx-1][fabric.m_nx-1] = 1.0;
             m_matrixRight[fabric.m_nx-1] =fabric.m_CVaporOuter;
        }

        /* Tf */
        if(!fabric.m_inContact)
        {
             m_matrixLeft[fabric.m_nx][fabric.m_nx]=-(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0
                                                      -fabric.m_deltaX*fabric.m_coeConvecHeatIn;

             m_matrixLeft[fabric.m_nx][fabric.m_nx+1]=(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0;
             m_matrixRight[fabric.m_nx]=-fabric.m_deltaX*fabric.m_coeConvecHeatIn*fabric.m_temperatureInner;

             if(fabric.m_layNumber==0 && bodymodel)
             {
                 m_matrixRight[fabric.m_nx]-= eSkin*fabric.m_deltaX*0.239*1.0e-4;
             }
        }
        else
        {
             m_matrixLeft[fabric.m_nx][fabric.m_nx] = 1.0;
             m_matrixRight[fabric.m_nx]= fabric.m_temperatureInner;
        }

        if(!fabric.m_outContact)
        {
             m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-1]=(fabric.m_thermoConductivity[fabric.m_nx-1]+fabric.m_thermoConductivity[fabric.m_nx-2])/2.0
                                                             +fabric.m_deltaX*fabric.m_coeConvecHeatOut;
             m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-2]=-(fabric.m_thermoConductivity[fabric.m_nx-1]+fabric.m_thermoConductivity[fabric.m_nx-2])/2.0;
             m_matrixRight[2*fabric.m_nx-1]=fabric.m_deltaX*fabric.m_coeConvecHeatOut*fabric.m_temperatureOuter;
        }
        else
        {
             m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-1]= 1.0;
             m_matrixRight[2*fabric.m_nx-1] = fabric.m_temperatureOuter;
        }

        if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
        {
            if(!fabric.m_inContact)
            {
                m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx]=-(fabric.m_diffusionCoeLiqWater[0]+fabric.m_diffusionCoeLiqWater[1])/2.0;
                m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx+1]=(fabric.m_diffusionCoeLiqWater[0]+fabric.m_diffusionCoeLiqWater[1])/2.0;
                m_matrixRight[2*fabric.m_nx]=fabric.m_CLiquidInner;
                /* second equation*/
                if(fabric.m_layNumber==0 && bodymodel)
                {
                    m_matrixRight[fabric.m_nx]+=fabric.m_heatInner;
                }
            }
            else
            {
                m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx] = 1.0;
                m_matrixRight[2*fabric.m_nx] = fabric.m_vLiquidInner;
            }

            if(!fabric.m_outContact)
            {
                m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-1]=(fabric.m_diffusionCoeLiqWater[fabric.m_nx-1]+fabric.m_diffusionCoeLiqWater[fabric.m_nx-2])/2.0;
                m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-2]=-(fabric.m_diffusionCoeLiqWater[fabric.m_nx-1]+fabric.m_diffusionCoeLiqWater[fabric.m_nx-2])/2.0;
                m_matrixRight[3*fabric.m_nx-1]=-fabric.m_CLiquidOuter;

                /* second equation*/
                m_matrixRight[2*fabric.m_nx-1]-= fabric.m_heatOuter;
            }
            else
            {
                m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-1] = 1.0;
                m_matrixRight[3*fabric.m_nx-1] = fabric.m_vLiquidOuter;
            }

        }

        if(fabric.m_modelFlag.compareTo(ModelType.AddPressure)>=0)
        {
            m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx]=1.0;
            m_matrixRight[3*fabric.m_nx]= fabric.m_pressureInner;

            m_matrixLeft[4*fabric.m_nx-1][4*fabric.m_nx-1]=1.0;
            m_matrixRight[4*fabric.m_nx-1]= fabric.m_pressureOuter;

            /* first equation */
            m_matrixLeft[0][3*fabric.m_nx]=-(fabric.m_coePressureWaterVapor[0]+fabric.m_coePressureWaterVapor[1])/2.0;
            m_matrixLeft[0][3*fabric.m_nx+1]=(fabric.m_coePressureWaterVapor[0]+fabric.m_coePressureWaterVapor[1])/2.0;

            m_matrixLeft[fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coePressureWaterVapor[fabric.m_nx-1]+fabric.m_coePressureWaterVapor[fabric.m_nx-2])/2.0;
            m_matrixLeft[fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coePressureWaterVapor[fabric.m_nx-1]+fabric.m_coePressureWaterVapor[fabric.m_nx-2])/2.0;

            /* third equation*/
            m_matrixLeft[2*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coePressureLiquidWater[0]+fabric.m_coePressureLiquidWater[1])/2.0;
            m_matrixLeft[2*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coePressureLiquidWater[0]+fabric.m_coePressureLiquidWater[1])/2.0;

            m_matrixLeft[3*fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coePressureLiquidWater[fabric.m_nx-1]+fabric.m_coePressureLiquidWater[fabric.m_nx-2])/2;
            m_matrixLeft[3*fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coePressureLiquidWater[fabric.m_nx-1]+fabric.m_coePressureLiquidWater[fabric.m_nx-2])/2.0;

        }
        if(fabric.m_modelFlag.compareTo(ModelType.AddVirus)>=0) //revise
        {
            m_matrixLeft[4*fabric.m_nx][4*fabric.m_nx]=-(fabric.m_coeDiffusionVirus[0]+fabric.m_coeDiffusionVirus[1])/2.0;
            m_matrixLeft[4*fabric.m_nx][4*fabric.m_nx+1]=(fabric.m_coeDiffusionVirus[0]+fabric.m_coeDiffusionVirus[1])/2.0;
            m_matrixRight[4*fabric.m_nx]=0.0;
            m_matrixLeft[5*fabric.m_nx-1][5*fabric.m_nx-1]=(fabric.m_coeDiffusionVirus[fabric.m_nx-1]+fabric.m_coeDiffusionVirus[fabric.m_nx-2])/2.0;
            m_matrixLeft[5*fabric.m_nx-1][5*fabric.m_nx-2]=-(fabric.m_coeDiffusionVirus[fabric.m_nx-1]+fabric.m_coeDiffusionVirus[fabric.m_nx-2])/2.0;
            m_matrixRight[5*fabric.m_nx-1]=0.0;

            /* fifth equation --liquid water */
            m_matrixLeft[4*fabric.m_nx][2*fabric.m_nx]=-(fabric.m_coeVirusToLiqWater[0]+fabric.m_coeVirusToLiqWater[1])/2.0;
            m_matrixLeft[4*fabric.m_nx][2*fabric.m_nx+1]=(fabric.m_coeVirusToLiqWater[0]+fabric.m_coeVirusToLiqWater[1])/2.0;
            m_matrixLeft[5*fabric.m_nx-1][3*fabric.m_nx-1]=(fabric.m_coeVirusToLiqWater[fabric.m_nx-1]+fabric.m_coeVirusToLiqWater[fabric.m_nx-2])/2.0;
            m_matrixLeft[5*fabric.m_nx-1][3*fabric.m_nx-2]=-(fabric.m_coeVirusToLiqWater[fabric.m_nx-1]+fabric.m_coeVirusToLiqWater[fabric.m_nx-2])/2.0;

            /* fifth equation --pressure*/
            m_matrixLeft[4*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coeVirusToPressure[0]+fabric.m_coeVirusToPressure[1])/2;
            m_matrixLeft[4*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coeVirusToPressure[0]+fabric.m_coeVirusToPressure[1])/2;
            m_matrixLeft[5*fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coeVirusToPressure[fabric.m_nx-1]+fabric.m_coeVirusToPressure[fabric.m_nx-2])/2.0;
            m_matrixLeft[5*fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coeVirusToPressure[fabric.m_nx-1]+fabric.m_coeVirusToPressure[fabric.m_nx-2])/2.0;

            /* some boundary condition need be update in this situation*/
            m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;
            m_matrixLeft[0][1]=(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;

            if(virus.m_velocityBreathOut>0.0)
            {
                m_matrixRight[0]=-virus.m_velocityBreathOut*fabric.m_CVaporInner*fabric.m_deltaX
                                 *fabric.m_vGas[0].preNodeValue*virus.m_ratioAreaNares;

            }
            else
            {
                m_matrixRight[0]=-virus.m_velocityBreathOut*fabric.m_cWaterVapor[0].preNodeValue
                                 *fabric.m_deltaX*fabric.m_vGas[0].preNodeValue*virus.m_ratioAreaNares;
            }

            m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coePressureGas[0]+fabric.m_coePressureGas[1])/2;
            m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coePressureGas[0]+fabric.m_coePressureGas[1])/2;

            if(virus.m_velocityBreathOut>0.0)
            {
                m_matrixRight[3*fabric.m_nx]=-virus.m_velocityBreathOut*fabric.m_porosity*fabric.m_deltaX*virus.m_ratioAreaNares
                                              *fabric.m_pressureInner*gas.m_moleMassGas
                                              /(gas.m_gasConstant*fabric.m_temperatureInner);

            }
            else
            {
                m_matrixRight[3*fabric.m_nx]=-virus.m_velocityBreathOut*fabric.m_porosity*fabric.m_deltaX*virus.m_ratioAreaNares
                                              *fabric.m_pressureGas[0].preNodeValue *gas.m_moleMassGas
                                              /(gas.m_gasConstant*fabric.m_tFabric[0].preNodeValue);

            }
        }

        if(fabric.m_modelFlag.compareTo(ModelType.AddNoLocal)>=0)
        {
            /* sixth equation */
            if(virus.m_velocityBreathOut>=0.0)
            {
                m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx]= 1.0;
                m_matrixRight[5*fabric.m_nx]=fabric.m_temperatureInner;
            }
            else
            {
                m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx]=-(fabric.m_coeDDeTg[0]*fabric.m_coeAfeTg[0]+fabric.m_coeFeTg[0])
                                                             -fabric.m_coeLocalEquiGas[0]*fabric.m_deltaX/fabric.m_deltaT;
                m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx+1]=fabric.m_coeDDeTg[0]*fabric.m_coeAfeTg[0]+fabric.m_coeFeTg[0];

                m_matrixRight[5*fabric.m_nx]=-fabric.m_coeLocalEquiGas[0]*fabric.m_deltaX*fabric.m_tGas[0].preNodeValue/fabric.m_deltaT
                                              -fabric.m_valueLocalEquiGas[0]*fabric.m_deltaT;

            }
            /* senventh equation*/
            if(virus.m_velocityBreathOut<=0.0)
            {
                m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-1]= 1.0;
                m_matrixRight[6*fabric.m_nx-1]=fabric.m_temperatureOuter;
            }
            else
            {
                m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-1]=-(fabric.m_coeDDwTg[fabric.m_nx-1]*fabric.m_coeAfwTg[fabric.m_nx-1]
                                                                 + fabric.m_coeFwTg[fabric.m_nx-1])
                                                                 -fabric.m_coeLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX/fabric.m_deltaT;

                m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-2]=fabric.m_coeDDwTg[fabric.m_nx-1]*fabric.m_coeAfwTg[fabric.m_nx-1]
                                                                 + fabric.m_coeFwTg[fabric.m_nx-1];

                m_matrixRight[6*fabric.m_nx-1]=-fabric.m_coeLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX*fabric.m_tGas[fabric.m_nx-1].preNodeValue/fabric.m_deltaT
                                                 -fabric.m_valueLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX;//*fabric.m_deltaT; //revise
            }
        }

    };

	void GetMatrixBoundarytyty(TNumericalFabric fabric, TNumericalGas gas, TNumericalLiquidWater liquid, TNumericalVirus virus,
		double eSkin,boolean bodymodel,TNumericalSelfHeating selfHeat,int i,float Pm, float Ph, double totalHeatEvaporation[])
	{
		Pm = Math.abs(Pm);
		while (Pm>1)
		{
			Pm /=100.0;
		}
		Ph = Math.abs(Ph);
		while (Ph>1)
		{
			Ph /=100.0;
		}

	    /* Ca */
	    if(!fabric.m_inContact)
	    {
	      //   m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0
	     //                      - fabric.m_coeConvecMassIn* fabric.m_deltaX*fabric.m_vGas[0].preNodeValue/fabric.m_porosity*(1-Pm);

	         m_matrixLeft[0][1]=(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;
			 if(fabric.m_layNumber==0)   // 如果该织物位于最内层，即贴近皮肤
			 {
				 m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0 - fabric.m_coeConvecMassIn* fabric.m_deltaX*fabric.m_vGas[0].preNodeValue/fabric.m_porosity*(1-Pm);
				 m_matrixRight[0]= -fabric.m_coeConvecMassIn*fabric.m_vGas[0].preNodeValue*fabric.m_deltaX*fabric.m_CVaporInner/fabric.m_porosity*(1-Pm) + Pm*fabric.m_deltaX*totalHeatEvaporation[4*i+3]/liquid.m_latentHeatEvaporation;
			 }
			 else
			 {
				 m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;
				 m_matrixRight[0]= -fabric.m_coeConvecMassIn*fabric.m_vGas[0].preNodeValue*fabric.m_deltaX*fabric.m_CVaporInner/fabric.m_porosity;
			 }
	    }
	    else
	    {
	         m_matrixLeft[0][0] = 1.0;
	         m_matrixRight[0] = fabric.m_CVaporInner;

	    }

	    if(!fabric.m_outContact)
	    {
	         m_matrixLeft[fabric.m_nx-1][fabric.m_nx-1]=fabric.m_coeConvecMassOut*fabric.m_vGas[fabric.m_nx-1].preNodeValue
	                                                     *fabric.m_deltaX/fabric.m_porosity
	                                                     +(fabric.m_coeWaterVapor[fabric.m_nx-1]+fabric.m_coeWaterVapor[fabric.m_nx-2])/2.0;

	         m_matrixLeft[fabric.m_nx-1][fabric.m_nx-2]= -(fabric.m_coeWaterVapor[fabric.m_nx-1]+fabric.m_coeWaterVapor[fabric.m_nx-2])/2.0;

	         m_matrixRight[fabric.m_nx-1]=fabric.m_coeConvecMassOut*fabric.m_deltaX *fabric.m_vGas[fabric.m_nx-1].preNodeValue
	                                      *fabric.m_CVaporOuter/fabric.m_porosity;

	    }
	    else
	    {
	         m_matrixLeft[fabric.m_nx-1][fabric.m_nx-1] = 1.0;
	         m_matrixRight[fabric.m_nx-1] =fabric.m_CVaporOuter;
	    }

	    /* T */
	    if(!fabric.m_inContact)
	    {
	       //  m_matrixLeft[fabric.m_nx][fabric.m_nx]=-(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0
	       //                                           -fabric.m_deltaX*fabric.m_coeConvecHeatIn*(1-Ph);

	         m_matrixLeft[fabric.m_nx][fabric.m_nx+1]=(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0;
	       /*  m_matrixRight[fabric.m_nx]=-fabric.m_deltaX*fabric.m_coeConvecHeatIn*fabric.m_temperatureInner;

	         if(!fabric.m_layNumber && bodymodel)
	         {
	             m_matrixRight[fabric.m_nx]-= eSkin*fabric.m_deltaX*0.239*1.0e-4;
	         }*/
			 if(fabric.m_layNumber==0)
			 {
				 m_matrixRight[fabric.m_nx]=-fabric.m_deltaX*fabric.m_coeConvecHeatIn*fabric.m_temperatureInner*(1-Ph)-Ph*fabric.m_deltaX*totalHeatEvaporation[4*i+3]-fabric.m_coeMassTransfer*fabric.m_deltaX*fabric.m_vLiquidWater[0].preNodeValue*(fabric.m_CVaporInner-TPhysicalPro.SaturatedWaterVaporP(fabric.m_temperatureInner));
				 m_matrixLeft[fabric.m_nx][fabric.m_nx]=-(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0 -fabric.m_deltaX*fabric.m_coeConvecHeatIn;
			 }
			 else
			 {
				 m_matrixLeft[fabric.m_nx][fabric.m_nx]=-(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0;
				 m_matrixRight[fabric.m_nx]=-fabric.m_deltaX*fabric.m_coeConvecHeatIn*fabric.m_temperatureInner;
			 }
		}
		else
		{
			m_matrixLeft[fabric.m_nx][fabric.m_nx] = 1.0;
			m_matrixRight[fabric.m_nx]= fabric.m_temperatureInner;
		}

		if(!fabric.m_outContact)
		{
			m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-1]=(fabric.m_thermoConductivity[fabric.m_nx-1]+fabric.m_thermoConductivity[fabric.m_nx-2])/2.0
				+fabric.m_deltaX*fabric.m_coeConvecHeatOut;
			m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-2]=-(fabric.m_thermoConductivity[fabric.m_nx-1]+fabric.m_thermoConductivity[fabric.m_nx-2])/2.0;
			m_matrixRight[2*fabric.m_nx-1]=fabric.m_deltaX*fabric.m_coeConvecHeatOut*fabric.m_temperatureOuter;
	    }
	    else
	    {
	         m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-1]= 1.0;
	         m_matrixRight[2*fabric.m_nx-1] = fabric.m_temperatureOuter;
	    }

	    if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
	    {
	        if(!fabric.m_inContact)
	        {
	            m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx]=-(fabric.m_diffusionCoeLiqWater[0]+fabric.m_diffusionCoeLiqWater[1])/2.0;
	            m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx+1]=(fabric.m_diffusionCoeLiqWater[0]+fabric.m_diffusionCoeLiqWater[1])/2.0;
	            m_matrixRight[2*fabric.m_nx]=fabric.m_CLiquidInner;
	            /* second equation*/
	            if(fabric.m_layNumber!=0 && bodymodel)
	            {
	                m_matrixRight[fabric.m_nx]+=fabric.m_heatInner;
	            }
	        }
	        else
	        {
	            m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx] = 1.0;
	            m_matrixRight[2*fabric.m_nx] = fabric.m_vLiquidInner;
	        }

	        if(!fabric.m_outContact)
	        {
	            m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-1]=(fabric.m_diffusionCoeLiqWater[fabric.m_nx-1]+fabric.m_diffusionCoeLiqWater[fabric.m_nx-2])/2.0;
	            m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-2]=-(fabric.m_diffusionCoeLiqWater[fabric.m_nx-1]+fabric.m_diffusionCoeLiqWater[fabric.m_nx-2])/2.0;
	            m_matrixRight[3*fabric.m_nx-1]=-fabric.m_CLiquidOuter;

	            /* second equation*/
	            m_matrixRight[2*fabric.m_nx-1]-= fabric.m_heatOuter;
	        }
	        else
	        {
	            m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-1] = 1.0;
	            m_matrixRight[3*fabric.m_nx-1] = fabric.m_vLiquidOuter;
	        }

	    }

	    if(fabric.m_modelFlag.compareTo(ModelType.AddPressure)>=0)
	    {
	        m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx]=1.0;
	        m_matrixRight[3*fabric.m_nx]= fabric.m_pressureInner;

	        m_matrixLeft[4*fabric.m_nx-1][4*fabric.m_nx-1]=1.0;
	        m_matrixRight[4*fabric.m_nx-1]= fabric.m_pressureOuter;

	        /* first equation */
	        m_matrixLeft[0][3*fabric.m_nx]=-(fabric.m_coePressureWaterVapor[0]+fabric.m_coePressureWaterVapor[1])/2.0;
	        m_matrixLeft[0][3*fabric.m_nx+1]=(fabric.m_coePressureWaterVapor[0]+fabric.m_coePressureWaterVapor[1])/2.0;

	        m_matrixLeft[fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coePressureWaterVapor[fabric.m_nx-1]+fabric.m_coePressureWaterVapor[fabric.m_nx-2])/2.0;
	        m_matrixLeft[fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coePressureWaterVapor[fabric.m_nx-1]+fabric.m_coePressureWaterVapor[fabric.m_nx-2])/2.0;

	        /* third equation*/
	        m_matrixLeft[2*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coePressureLiquidWater[0]+fabric.m_coePressureLiquidWater[1])/2.0;
	        m_matrixLeft[2*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coePressureLiquidWater[0]+fabric.m_coePressureLiquidWater[1])/2.0;

	        m_matrixLeft[3*fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coePressureLiquidWater[fabric.m_nx-1]+fabric.m_coePressureLiquidWater[fabric.m_nx-2])/2;
	        m_matrixLeft[3*fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coePressureLiquidWater[fabric.m_nx-1]+fabric.m_coePressureLiquidWater[fabric.m_nx-2])/2.0;

	    }
	    if(fabric.m_modelFlag.compareTo(ModelType.AddVirus)>=0) //revise
	    {
	        m_matrixLeft[4*fabric.m_nx][4*fabric.m_nx]=-(fabric.m_coeDiffusionVirus[0]+fabric.m_coeDiffusionVirus[1])/2.0;
	        m_matrixLeft[4*fabric.m_nx][4*fabric.m_nx+1]=(fabric.m_coeDiffusionVirus[0]+fabric.m_coeDiffusionVirus[1])/2.0;
	        m_matrixRight[4*fabric.m_nx]=0.0;
	        m_matrixLeft[5*fabric.m_nx-1][5*fabric.m_nx-1]=(fabric.m_coeDiffusionVirus[fabric.m_nx-1]+fabric.m_coeDiffusionVirus[fabric.m_nx-2])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][5*fabric.m_nx-2]=-(fabric.m_coeDiffusionVirus[fabric.m_nx-1]+fabric.m_coeDiffusionVirus[fabric.m_nx-2])/2.0;
	        m_matrixRight[5*fabric.m_nx-1]=0.0;

	        /* fifth equation --liquid water */
	        m_matrixLeft[4*fabric.m_nx][2*fabric.m_nx]=-(fabric.m_coeVirusToLiqWater[0]+fabric.m_coeVirusToLiqWater[1])/2.0;
	        m_matrixLeft[4*fabric.m_nx][2*fabric.m_nx+1]=(fabric.m_coeVirusToLiqWater[0]+fabric.m_coeVirusToLiqWater[1])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][3*fabric.m_nx-1]=(fabric.m_coeVirusToLiqWater[fabric.m_nx-1]+fabric.m_coeVirusToLiqWater[fabric.m_nx-2])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][3*fabric.m_nx-2]=-(fabric.m_coeVirusToLiqWater[fabric.m_nx-1]+fabric.m_coeVirusToLiqWater[fabric.m_nx-2])/2.0;

	        /* fifth equation --pressure*/
	        m_matrixLeft[4*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coeVirusToPressure[0]+fabric.m_coeVirusToPressure[1])/2;
	        m_matrixLeft[4*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coeVirusToPressure[0]+fabric.m_coeVirusToPressure[1])/2;
	        m_matrixLeft[5*fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coeVirusToPressure[fabric.m_nx-1]+fabric.m_coeVirusToPressure[fabric.m_nx-2])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coeVirusToPressure[fabric.m_nx-1]+fabric.m_coeVirusToPressure[fabric.m_nx-2])/2.0;

	        /* some boundary condition need be update in this situation*/
	        m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;
	        m_matrixLeft[0][1]=(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;

	        if(virus.m_velocityBreathOut>0.0)
	        {
	            m_matrixRight[0]=-virus.m_velocityBreathOut*fabric.m_CVaporInner*fabric.m_deltaX
	                             *fabric.m_vGas[0].preNodeValue*virus.m_ratioAreaNares;

	        }
	        else
	        {
	            m_matrixRight[0]=-virus.m_velocityBreathOut*fabric.m_cWaterVapor[0].preNodeValue
	                             *fabric.m_deltaX*fabric.m_vGas[0].preNodeValue*virus.m_ratioAreaNares;
	        }

	        m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coePressureGas[0]+fabric.m_coePressureGas[1])/2;
	        m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coePressureGas[0]+fabric.m_coePressureGas[1])/2;

	        if(virus.m_velocityBreathOut>0.0)
	        {
	            m_matrixRight[3*fabric.m_nx]=-virus.m_velocityBreathOut*fabric.m_porosity*fabric.m_deltaX*virus.m_ratioAreaNares
	                                          *fabric.m_pressureInner*gas.m_moleMassGas
	                                          /(gas.m_gasConstant*fabric.m_temperatureInner);

	        }
	        else
	        {
	            m_matrixRight[3*fabric.m_nx]=-virus.m_velocityBreathOut*fabric.m_porosity*fabric.m_deltaX*virus.m_ratioAreaNares
	                                          *fabric.m_pressureGas[0].preNodeValue *gas.m_moleMassGas
	                                          /(gas.m_gasConstant*fabric.m_tFabric[0].preNodeValue);

	        }
	    }

	    if(fabric.m_modelFlag.compareTo(ModelType.AddNoLocal)>=0)
	    {
	        /* sixth equation */
	        if(virus.m_velocityBreathOut>=0.0)
	        {
	            m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx]= 1.0;
	            m_matrixRight[5*fabric.m_nx]=fabric.m_temperatureInner;
	        }
	        else
	        {
	            m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx]=-(fabric.m_coeDDeTg[0]*fabric.m_coeAfeTg[0]+fabric.m_coeFeTg[0])
	                                                         -fabric.m_coeLocalEquiGas[0]*fabric.m_deltaX/fabric.m_deltaT;
	            m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx+1]=fabric.m_coeDDeTg[0]*fabric.m_coeAfeTg[0]+fabric.m_coeFeTg[0];

	            m_matrixRight[5*fabric.m_nx]=-fabric.m_coeLocalEquiGas[0]*fabric.m_deltaX*fabric.m_tGas[0].preNodeValue/fabric.m_deltaT
	                                          -fabric.m_valueLocalEquiGas[0]*fabric.m_deltaT;

	        }
	        /* senventh equation*/
	        if(virus.m_velocityBreathOut<=0.0)
	        {
	            m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-1]= 1.0;
	            m_matrixRight[6*fabric.m_nx-1]=fabric.m_temperatureOuter;
	        }
	        else
	        {
	            m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-1]=-(fabric.m_coeDDwTg[fabric.m_nx-1]*fabric.m_coeAfwTg[fabric.m_nx-1]
	                                                             + fabric.m_coeFwTg[fabric.m_nx-1])
	                                                             -fabric.m_coeLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX/fabric.m_deltaT;

	            m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-2]=fabric.m_coeDDwTg[fabric.m_nx-1]*fabric.m_coeAfwTg[fabric.m_nx-1]
	                                                             + fabric.m_coeFwTg[fabric.m_nx-1];

	            m_matrixRight[6*fabric.m_nx-1]=-fabric.m_coeLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX*fabric.m_tGas[fabric.m_nx-1].preNodeValue/fabric.m_deltaT
	                                             -fabric.m_valueLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX;//*fabric.m_deltaT; //revise
	        }
	    }
	};

	void GetMatrixBoundaryTY(int i,TNumericalFabric fabric,TNumericalGas gas ,
		TNumericalLiquidWater liquid,TNumericalVirus virus,
		double eSkin,boolean bodymodel,TNumericalSelfHeating selfHeat,float Pm[], float Ph[],double totalHeatEvaporation[])
	{
		/* Ca */
	    if(!fabric.m_inContact)
		{
			m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0
			- fabric.m_coeConvecMassIn* fabric.m_deltaX*fabric.m_vGas[0].preNodeValue/fabric.m_porosity;

			m_matrixLeft[0][1]=(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;
			if(fabric.m_layNumber==0)   // next to the skin surface
			{
				m_matrixRight[0]= -fabric.m_coeConvecMassIn*fabric.m_vGas[0].preNodeValue*fabric.m_deltaX*fabric.m_CVaporInner/fabric.m_porosity*(1-Pm[i]) + Pm[i]*fabric.m_deltaX*totalHeatEvaporation[4*i+3];
			}
			else
			{
				m_matrixRight[0]= -fabric.m_coeConvecMassIn*fabric.m_vGas[0].preNodeValue*fabric.m_deltaX*fabric.m_CVaporInner/fabric.m_porosity;
			}
	        

	    }
	    else
	    {
	         m_matrixLeft[0][0] = 1.0;
	         m_matrixRight[0] = fabric.m_CVaporInner;

	    }

	    if(!fabric.m_outContact)
	    {
	         m_matrixLeft[fabric.m_nx-1][fabric.m_nx-1]=fabric.m_coeConvecMassOut*fabric.m_vGas[fabric.m_nx-1].preNodeValue
	                                                     *fabric.m_deltaX/fabric.m_porosity
	                                                     +(fabric.m_coeWaterVapor[fabric.m_nx-1]+fabric.m_coeWaterVapor[fabric.m_nx-2])/2.0;

	         m_matrixLeft[fabric.m_nx-1][fabric.m_nx-2]= -(fabric.m_coeWaterVapor[fabric.m_nx-1]+fabric.m_coeWaterVapor[fabric.m_nx-2])/2.0;

	         m_matrixRight[fabric.m_nx-1]=fabric.m_coeConvecMassOut*fabric.m_deltaX *fabric.m_vGas[fabric.m_nx-1].preNodeValue
	                                      *fabric.m_CVaporOuter/fabric.m_porosity;

	    }
	    else
	    {
	         m_matrixLeft[fabric.m_nx-1][fabric.m_nx-1] = 1.0;
	         m_matrixRight[fabric.m_nx-1] =fabric.m_CVaporOuter;
	    }

	    /* T */
	    if(!fabric.m_inContact)
	    {
	         m_matrixLeft[fabric.m_nx][fabric.m_nx]=-(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0
	                                                  -fabric.m_deltaX*fabric.m_coeConvecHeatIn;

	         m_matrixLeft[fabric.m_nx][fabric.m_nx+1]=(fabric.m_thermoConductivity[0]+fabric.m_thermoConductivity[1])/2.0;

			 if(fabric.m_layNumber==0)
			 {
				 m_matrixRight[fabric.m_nx]=-fabric.m_deltaX*fabric.m_coeConvecHeatIn*fabric.m_temperatureInner*(1-Ph[i])-Ph[i]*fabric.m_deltaX*totalHeatEvaporation[4*i+3]-fabric.m_coeMassTransfer*fabric.m_deltaX*fabric.m_vLiquidWater[0].preNodeValue*(fabric.m_CVaporInner-TPhysicalPro.SaturatedWaterVaporP(fabric.m_temperatureInner));
				
			 }
			 else
			 {
				m_matrixRight[fabric.m_nx]=-fabric.m_deltaX*fabric.m_coeConvecHeatIn*fabric.m_temperatureInner;
			 }
	         if(fabric.m_layNumber==0 && bodymodel)
	         {
	             m_matrixRight[fabric.m_nx]-= eSkin*fabric.m_deltaX*0.239*1.0e-4;
	         }
	    }
	    else
	    {
	         m_matrixLeft[fabric.m_nx][fabric.m_nx] = 1.0;
	         m_matrixRight[fabric.m_nx]= fabric.m_temperatureInner;
	    }

	    if(!fabric.m_outContact)
	    {
	         m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-1]=(fabric.m_thermoConductivity[fabric.m_nx-1]+fabric.m_thermoConductivity[fabric.m_nx-2])/2.0
	                                                         +fabric.m_deltaX*fabric.m_coeConvecHeatOut;
	         m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-2]=-(fabric.m_thermoConductivity[fabric.m_nx-1]+fabric.m_thermoConductivity[fabric.m_nx-2])/2.0;
	         m_matrixRight[2*fabric.m_nx-1]=fabric.m_deltaX*fabric.m_coeConvecHeatOut*fabric.m_temperatureOuter-fabric.m_coeMassTransfer*fabric.m_deltaX*fabric.m_vLiquidWater[fabric.m_nx-1].preNodeValue*(fabric.m_CVaporInner-TPhysicalPro.SaturatedWaterVaporP(fabric.m_temperatureOuter));;
	    }
	    else
	    {
	         m_matrixLeft[2*fabric.m_nx-1][2*fabric.m_nx-1]= 1.0;
	         m_matrixRight[2*fabric.m_nx-1] = fabric.m_temperatureOuter;
	    }

	    if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
	    {
	        if(!fabric.m_inContact)
	        {
	            m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx]=-(fabric.m_diffusionCoeLiqWater[0]+fabric.m_diffusionCoeLiqWater[1])/2.0;
	            m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx+1]=(fabric.m_diffusionCoeLiqWater[0]+fabric.m_diffusionCoeLiqWater[1])/2.0;
	            m_matrixRight[2*fabric.m_nx]=-fabric.m_coeMassTransfer*fabric.m_deltaX*fabric.m_vLiquidWater[0].preNodeValue*(fabric.m_CVaporInner-TPhysicalPro.SaturatedWaterVaporP(fabric.m_temperatureInner));
	            /* second equation*/
	            if(fabric.m_layNumber!=0 && bodymodel)
	            {
	                m_matrixRight[fabric.m_nx]+=fabric.m_heatInner;
	            }
	        }
	        else
	        {
	            m_matrixLeft[2*fabric.m_nx][2*fabric.m_nx] = 1.0;
	            m_matrixRight[2*fabric.m_nx] = fabric.m_vLiquidInner;
	        }

	        if(!fabric.m_outContact)
	        {
	            m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-1]=(fabric.m_diffusionCoeLiqWater[fabric.m_nx-1]+fabric.m_diffusionCoeLiqWater[fabric.m_nx-2])/2.0;
	            m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-2]=-(fabric.m_diffusionCoeLiqWater[fabric.m_nx-1]+fabric.m_diffusionCoeLiqWater[fabric.m_nx-2])/2.0;
	            m_matrixRight[3*fabric.m_nx-1]=-fabric.m_coeMassTransfer*fabric.m_deltaX*fabric.m_vLiquidWater[fabric.m_nx-1].preNodeValue*(fabric.m_CVaporInner-TPhysicalPro.SaturatedWaterVaporP(fabric.m_temperatureOuter));

	            /* second equation*/
	            m_matrixRight[2*fabric.m_nx-1]-= fabric.m_heatOuter;
	        }
	        else
	        {
	            m_matrixLeft[3*fabric.m_nx-1][3*fabric.m_nx-1] = 1.0;
	            m_matrixRight[3*fabric.m_nx-1] = fabric.m_vLiquidOuter;
	        }

	    }

	    if(fabric.m_modelFlag.compareTo(ModelType.AddPressure)>=0)
	    {
	        m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx]=1.0;
	        m_matrixRight[3*fabric.m_nx]= fabric.m_pressureInner;

	        m_matrixLeft[4*fabric.m_nx-1][4*fabric.m_nx-1]=1.0;
	        m_matrixRight[4*fabric.m_nx-1]= fabric.m_pressureOuter;

	        /* first equation */
	        m_matrixLeft[0][3*fabric.m_nx]=-(fabric.m_coePressureWaterVapor[0]+fabric.m_coePressureWaterVapor[1])/2.0;
	        m_matrixLeft[0][3*fabric.m_nx+1]=(fabric.m_coePressureWaterVapor[0]+fabric.m_coePressureWaterVapor[1])/2.0;

	        m_matrixLeft[fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coePressureWaterVapor[fabric.m_nx-1]+fabric.m_coePressureWaterVapor[fabric.m_nx-2])/2.0;
	        m_matrixLeft[fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coePressureWaterVapor[fabric.m_nx-1]+fabric.m_coePressureWaterVapor[fabric.m_nx-2])/2.0;

	        /* third equation*/
	        m_matrixLeft[2*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coePressureLiquidWater[0]+fabric.m_coePressureLiquidWater[1])/2.0;
	        m_matrixLeft[2*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coePressureLiquidWater[0]+fabric.m_coePressureLiquidWater[1])/2.0;

	        m_matrixLeft[3*fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coePressureLiquidWater[fabric.m_nx-1]+fabric.m_coePressureLiquidWater[fabric.m_nx-2])/2;
	        m_matrixLeft[3*fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coePressureLiquidWater[fabric.m_nx-1]+fabric.m_coePressureLiquidWater[fabric.m_nx-2])/2.0;

	    }
	    if(fabric.m_modelFlag.compareTo(ModelType.AddVirus)>=0) //revise
	    {
	        m_matrixLeft[4*fabric.m_nx][4*fabric.m_nx]=-(fabric.m_coeDiffusionVirus[0]+fabric.m_coeDiffusionVirus[1])/2.0;
	        m_matrixLeft[4*fabric.m_nx][4*fabric.m_nx+1]=(fabric.m_coeDiffusionVirus[0]+fabric.m_coeDiffusionVirus[1])/2.0;
	        m_matrixRight[4*fabric.m_nx]=0.0;
	        m_matrixLeft[5*fabric.m_nx-1][5*fabric.m_nx-1]=(fabric.m_coeDiffusionVirus[fabric.m_nx-1]+fabric.m_coeDiffusionVirus[fabric.m_nx-2])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][5*fabric.m_nx-2]=-(fabric.m_coeDiffusionVirus[fabric.m_nx-1]+fabric.m_coeDiffusionVirus[fabric.m_nx-2])/2.0;
	        m_matrixRight[5*fabric.m_nx-1]=0.0;

	        /* fifth equation --liquid water */
	        m_matrixLeft[4*fabric.m_nx][2*fabric.m_nx]=-(fabric.m_coeVirusToLiqWater[0]+fabric.m_coeVirusToLiqWater[1])/2.0;
	        m_matrixLeft[4*fabric.m_nx][2*fabric.m_nx+1]=(fabric.m_coeVirusToLiqWater[0]+fabric.m_coeVirusToLiqWater[1])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][3*fabric.m_nx-1]=(fabric.m_coeVirusToLiqWater[fabric.m_nx-1]+fabric.m_coeVirusToLiqWater[fabric.m_nx-2])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][3*fabric.m_nx-2]=-(fabric.m_coeVirusToLiqWater[fabric.m_nx-1]+fabric.m_coeVirusToLiqWater[fabric.m_nx-2])/2.0;

	        /* fifth equation --pressure*/
	        m_matrixLeft[4*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coeVirusToPressure[0]+fabric.m_coeVirusToPressure[1])/2;
	        m_matrixLeft[4*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coeVirusToPressure[0]+fabric.m_coeVirusToPressure[1])/2;
	        m_matrixLeft[5*fabric.m_nx-1][4*fabric.m_nx-1]=(fabric.m_coeVirusToPressure[fabric.m_nx-1]+fabric.m_coeVirusToPressure[fabric.m_nx-2])/2.0;
	        m_matrixLeft[5*fabric.m_nx-1][4*fabric.m_nx-2]=-(fabric.m_coeVirusToPressure[fabric.m_nx-1]+fabric.m_coeVirusToPressure[fabric.m_nx-2])/2.0;

	        /* some boundary condition need be update in this situation*/
	        m_matrixLeft[0][0]=-(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;
	        m_matrixLeft[0][1]=(fabric.m_coeWaterVapor[0]+fabric.m_coeWaterVapor[1])/2.0;

	        if(virus.m_velocityBreathOut>0.0)
	        {
	            m_matrixRight[0]=-virus.m_velocityBreathOut*fabric.m_CVaporInner*fabric.m_deltaX
	                             *fabric.m_vGas[0].preNodeValue*virus.m_ratioAreaNares;

	        }
	        else
	        {
	            m_matrixRight[0]=-virus.m_velocityBreathOut*fabric.m_cWaterVapor[0].preNodeValue
	                             *fabric.m_deltaX*fabric.m_vGas[0].preNodeValue*virus.m_ratioAreaNares;
	        }

	        m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx]=-(fabric.m_coePressureGas[0]+fabric.m_coePressureGas[1])/2;
	        m_matrixLeft[3*fabric.m_nx][3*fabric.m_nx+1]=(fabric.m_coePressureGas[0]+fabric.m_coePressureGas[1])/2;

	        if(virus.m_velocityBreathOut>0.0)
	        {
	            m_matrixRight[3*fabric.m_nx]=-virus.m_velocityBreathOut*fabric.m_porosity*fabric.m_deltaX*virus.m_ratioAreaNares
	                                          *fabric.m_pressureInner*gas.m_moleMassGas
	                                          /(gas.m_gasConstant*fabric.m_temperatureInner);

	        }
	        else
	        {
	            m_matrixRight[3*fabric.m_nx]=-virus.m_velocityBreathOut*fabric.m_porosity*fabric.m_deltaX*virus.m_ratioAreaNares
	                                          *fabric.m_pressureGas[0].preNodeValue *gas.m_moleMassGas
	                                          /(gas.m_gasConstant*fabric.m_tFabric[0].preNodeValue);

	        }
	    }

	    if(fabric.m_modelFlag.compareTo(ModelType.AddNoLocal)>=0)
	    {
	        /* sixth equation */
	        if(virus.m_velocityBreathOut>=0.0)
	        {
	            m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx]= 1.0;
	            m_matrixRight[5*fabric.m_nx]=fabric.m_temperatureInner;
	        }
	        else
	        {
	            m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx]=-(fabric.m_coeDDeTg[0]*fabric.m_coeAfeTg[0]+fabric.m_coeFeTg[0])
	                                                         -fabric.m_coeLocalEquiGas[0]*fabric.m_deltaX/fabric.m_deltaT;
	            m_matrixLeft[5*fabric.m_nx][5*fabric.m_nx+1]=fabric.m_coeDDeTg[0]*fabric.m_coeAfeTg[0]+fabric.m_coeFeTg[0];

	            m_matrixRight[5*fabric.m_nx]=-fabric.m_coeLocalEquiGas[0]*fabric.m_deltaX*fabric.m_tGas[0].preNodeValue/fabric.m_deltaT
	                                          -fabric.m_valueLocalEquiGas[0]*fabric.m_deltaT;

	        }
	        /* senventh equation*/
	        if(virus.m_velocityBreathOut<=0.0)
	        {
	            m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-1]= 1.0;
	            m_matrixRight[6*fabric.m_nx-1]=fabric.m_temperatureOuter;
	        }
	        else
	        {
	            m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-1]=-(fabric.m_coeDDwTg[fabric.m_nx-1]*fabric.m_coeAfwTg[fabric.m_nx-1]
	                                                             + fabric.m_coeFwTg[fabric.m_nx-1])
	                                                             -fabric.m_coeLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX/fabric.m_deltaT;

	            m_matrixLeft[6*fabric.m_nx-1][6*fabric.m_nx-2]=fabric.m_coeDDwTg[fabric.m_nx-1]*fabric.m_coeAfwTg[fabric.m_nx-1]
	                                                             + fabric.m_coeFwTg[fabric.m_nx-1];

	            m_matrixRight[6*fabric.m_nx-1]=-fabric.m_coeLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX*fabric.m_tGas[fabric.m_nx-1].preNodeValue/fabric.m_deltaT
	                                             -fabric.m_valueLocalEquiGas[fabric.m_nx-1]*fabric.m_deltaX;//*fabric.m_deltaT; //revise
	        }
	    }
	};

    void UpdateCoefficientValue(TNumericalFabric fabric,TNumericalGas gas,
                                TNumericalLiquidWater liquid,TNumericalVirus virus
                                )
    {
    	double thermoConductivityPCM = 0.0;
        int flagPCM = 0;
        TNumericalFiber fiber;

        for(int i=0;i<fabric.m_nx;i++)
        {
            fabric.m_cWaterVapor[i].nextNodeValue=m_matrixRight[i];//(fabs(m_matrixRight[i])+m_matrixRight[i])/2.0;
            if(fabric.m_cWaterVapor[i].nextNodeValue<0.0)
            {
                fabric.m_cWaterVapor[i].nextNodeValue=1.0e-8;
    		}

            fabric.m_tFabric[i].nextNodeValue = m_matrixRight[fabric.m_nx+i];
    		
            fabric.m_vGas[i].nextNodeValue = fabric.m_porosity ;

            if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
            {
                if(m_matrixRight[2*fabric.m_nx+i]<0.0)
                {
                    fabric.m_vLiquidWater[i].nextNodeValue =1.0e-5;
                }
                else
                {
                    fabric.m_vLiquidWater[i].nextNodeValue=m_matrixRight[2*fabric.m_nx+i];
                }
               // fabric.m_vLiquidWater[i].nextNodeValue = (fabs(m_matrixRight[2*fabric.m_nx+i])+m_matrixRight[2*fabric.m_nx+i])/2.0;

                fabric.m_vGas[i].nextNodeValue -= fabric.m_vLiquidWater[i].nextNodeValue; //revise
            }

            if(fabric.m_modelFlag.compareTo(ModelType.AddPressure)>=0)
            {
                fabric.m_pressureGas[i].nextNodeValue = m_matrixRight[3*fabric.m_nx+i];
            }

            if(fabric.m_modelFlag.compareTo(ModelType.AddNoLocal)>=0)
            {
                fabric.m_tGas[i].nextNodeValue = m_matrixRight[5*fabric.m_nx+i];
            }
            
            if(fabric.m_modelFlag.compareTo(ModelType.AddVirus)>=0)
            {
                fabric.m_cVirusInLiqWater[i].nextNodeValue = m_matrixRight[4*fabric.m_nx+i];
                fabric.m_vGas[i].nextNodeValue -= fabric.m_vVirus[i].nextNodeValue;
            }
            

            if(fabric.m_sourceItem.PCM)
            {
                if(fabric.m_tFabric[i].preNodeValue > fabric.m_pcm.m_meltingTemperature
                   && fabric.m_tFabric[i].nextNodeValue> fabric.m_pcm.m_meltingTemperature)
                {
                    thermoConductivityPCM=fabric.m_pcm.m_thermoLiqConductivity;
                    flagPCM=1;
                }
                else if(fabric.m_tFabric[i].preNodeValue < fabric.m_pcm.m_meltingTemperature
                        && fabric.m_tFabric[i].nextNodeValue < fabric.m_pcm.m_meltingTemperature)
                {
                    thermoConductivityPCM=fabric.m_pcm.m_thermoSolidConductivity;
                    flagPCM=-1;
                }
                else if(fabric.m_tFabric[i].preNodeValue >= fabric.m_pcm.m_meltingTemperature
                        && fabric.m_tFabric[i].nextNodeValue <= fabric.m_pcm.m_meltingTemperature)
                {
                    thermoConductivityPCM=fabric.m_pcm.m_thermoSolidConductivity;
                    flagPCM=0;
                }
                else if(fabric.m_tFabric[i].preNodeValue <= fabric.m_pcm.m_meltingTemperature
                        && fabric.m_tFabric[i].nextNodeValue >= fabric.m_pcm.m_meltingTemperature)
                {
                    thermoConductivityPCM=fabric.m_pcm.m_thermoLiqConductivity;
                    flagPCM=0;
                }

                if(flagPCM==0)
                {
                    fabric.m_heatLossPCM[i] = -3.0*fabric.m_vPCM*fabric.m_pcm.m_heatTransferCoe*(fabric.m_pcm.m_meltingTemperature-fabric.m_tFabric[i].nextNodeValue)/fabric.m_pcm.m_radius ;
                    fabric.m_radiusInterfacePCM[i].nextNodeValue=fabric.m_pcm.m_radius ;
                }
                else
                {
                    if(fabric.m_radiusInterfacePCM[i].preNodeValue>=2.0e-20)
                    {
                        fabric.m_movingVelocityPCM[i]=fabric.m_pcm.m_heatTransferCoe*thermoConductivityPCM * Math.pow(fabric.m_pcm.m_radius,2)*(fabric.m_pcm.m_meltingTemperature-fabric.m_tFabric[i].preNodeValue)
                                                       /(fabric.m_pcm.m_heatTransferCoe*Math.pow(fabric.m_pcm.m_radius,2)*fabric.m_radiusInterfacePCM[i].preNodeValue +(thermoConductivityPCM-fabric.m_pcm.m_heatTransferCoe*fabric.m_pcm.m_radius)
                                                       *Math.pow(fabric.m_radiusInterfacePCM[i].preNodeValue,2))/(fabric.m_pcm.m_density*fabric.m_pcm.m_latentHeatPCM);

                    }
                    else
                    {
                        fabric.m_movingVelocityPCM[i]=0.0;
                    }

                    fabric.m_radiusInterfacePCM[i].nextNodeValue= fabric.m_radiusInterfacePCM[i].preNodeValue+ flagPCM*fabric.m_movingVelocityPCM[i]*fabric.m_deltaT;

                    if(fabric.m_radiusInterfacePCM[i].nextNodeValue<=2.0e-20)
                    {
                        fabric.m_radiusInterfacePCM[i].nextNodeValue=2.0e-20 ;
                    }
                    else if(fabric.m_radiusInterfacePCM[i].nextNodeValue>=fabric.m_pcm.m_radius)
                    {
                        fabric.m_radiusInterfacePCM[i].nextNodeValue=fabric.m_pcm.m_radius ;
                    }

                    fabric.m_heatLossPCM[i] = -3.0*fabric.m_vPCM*fabric.m_pcm.m_heatTransferCoe*thermoConductivityPCM*(fabric.m_pcm.m_meltingTemperature-fabric.m_tFabric[i].nextNodeValue)
                                                             /(fabric.m_pcm.m_heatTransferCoe*fabric.m_pcm.m_radius*(fabric.m_pcm.m_radius/fabric.m_radiusInterfacePCM[i].nextNodeValue -1.0)+thermoConductivityPCM)
                                                             /fabric.m_pcm.m_radius;
                } //end else
            }//end if

            fabric.m_RH[i]= fabric.m_cWaterVapor[i].nextNodeValue
               /TPhysicalPro.WaterVaporConcentration(fabric.m_tFabric[i].nextNodeValue);
           
            if(fabric.m_RH[i]>1.0)
            {
                fabric.m_RH[i]=1.0;
            }

            fabric.m_meanCWaterVaporInFibers[i]=0;
            fabric.m_differentialWaterVapor[i]=0;
            fabric.m_wWaterVaporInFibers[i]=0;
            for(int k=0;k<fabric.m_includedFibers.size();k++)
            {
                fiber=(TNumericalFiber)fabric.m_includedFibers.get(k);

                fiber.SolveMoistureSorption(i,fabric.m_RH[i],fabric.m_deltaT);
                fabric.m_meanCWaterVaporInFibers[i]+= fiber.m_cMeanWaterVaporInFiber[i]*fiber.m_massRatio;
                fabric.m_differentialWaterVapor[i] +=fiber.m_differentialWaterVapor[i]*fiber.m_massRatio;
                fabric.m_wWaterVaporInFibers[i]+=fiber.m_wWaterVaporInFiber[i]*fiber.m_massRatio;

                for(int j=0;j<fiber.m_nr;j++)
                {
                    fiber.m_cWaterVaporInFiber[i][j].preNodeValue =  fiber.m_cWaterVaporInFiber[i][j].nextNodeValue;
                }
            }
            fabric.m_meanCInFibers[i]= fabric.m_meanCWaterVaporInFibers[i];
            fabric.m_meanWWaterInFibers[i]= fabric.m_wWaterVaporInFibers[i];

            if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
            {
                //fabric.m_differentialLiquidWater[i] =fabric.m_differentialWaterVapor[i];
                fabric.m_meanCLiquidWaterInFibers[i]=0;
                fabric.m_differentialLiquidWater[i]=0;
                fabric.m_wLiquidWaterInFibers[i]=0;
                for(int k=0;k<fabric.m_includedFibers.size();k++)
                {
                    fiber=(TNumericalFiber)fabric.m_includedFibers.get(k);
                    fiber.SolveLiquidSorption(i,fiber.m_density*fiber.m_regainY[16-1],fabric.m_deltaT);

                    fabric.m_meanCLiquidWaterInFibers[i] += fiber.m_cMeanLiquidWaterInFiber[i] *fiber.m_massRatio;
                    fabric.m_differentialLiquidWater[i]+=fiber.m_differentialLiquidWater[i]*fiber.m_massRatio;
                    fabric.m_wLiquidWaterInFibers[i]+=fiber.m_wLiquidWaterInFiber[i]*fiber.m_massRatio;

                    for(int j=0;j<fiber.m_nr;j++)
                    {
                        fiber.m_cLiquidWaterInFiber[i][j].preNodeValue =  fiber.m_cLiquidWaterInFiber[i][j].nextNodeValue;
                    }
                }
                //revise
                fabric.m_vSorbtionProportion=(1.0 -Math.pow((fabric.m_vLiquidWater[i].nextNodeValue/fabric.m_porosity),0.3))
                                             *fabric.m_vGas[i].nextNodeValue/fabric.m_porosity;
                fabric.m_lSorbtionProportion=1-fabric.m_vSorbtionProportion;
                fabric.m_meanCInFibers[i] = fabric.m_vSorbtionProportion*fabric.m_meanCWaterVaporInFibers[i]
                                                          +fabric.m_lSorbtionProportion*fabric.m_meanCLiquidWaterInFibers[i];
                fabric.m_meanWWaterInFibers[i]= fabric.m_vSorbtionProportion*fabric.m_wWaterVaporInFibers[i]
                                                +fabric.m_lSorbtionProportion*fabric.m_wLiquidWaterInFibers[i];



            }//end for if

            /* update cv, Kmix, cp*/
            fabric.m_volumetricHeatCapacity[i]=0;
            fabric.m_specificHeatCapacity[i]=0;

            fabric.m_meanFiberK=0;

            for(int k=0;k<fabric.m_includedFibers.size();k++)
            {
                fiber=(TNumericalFiber)fabric.m_includedFibers.get(k);
                fiber.m_specificHeatCapacity[i] = (0.32+fiber.m_wWaterVaporInFiber[i])
                                                          /(1+fiber.m_wWaterVaporInFiber[i]);

                //fiber.m_volumetricHeatCapacity[i]= fiber.m_density*fiber.m_specificHeatCapacity[i];

                //fabric.m_volumetricHeatCapacity[i]+= fiber.m_volumetricHeatCapacity[i]*fiber.m_massRatio;

                fabric.m_meanFiberK += fiber.GetThermolConductivity(fiber.m_wWaterVaporInFiber[i])*fiber.m_massRatio ;  //bug

                fabric.m_specificHeatCapacity[i]+= fiber.m_specificHeatCapacity[i]*fiber.m_massRatio;


            }

            fabric.m_volumetricHeatCapacity[i]=fabric.m_meanFiberDensity*(0.32+fabric.m_meanWWaterInFibers[i])
                                                           /(1+fabric.m_meanWWaterInFibers[i]);

            fabric.m_volumetricHeatCapacity[i]= fabric.m_volumetricHeatCapacity[i]*fabric.m_vFibers
                                                + gas.m_density* gas.m_sHeatCapacity *fabric.m_vGas[i].nextNodeValue;

            fabric.m_thermoConductivity[i] = fabric.m_meanFiberK//*fabric.m_vFibers
                                              +gas.m_thermoConductivityGas*fabric.m_vGas[i].nextNodeValue;

             //mao
            fabric.m_surfaceVolumeRatio[i]=2.0*fabric.m_vFibers*fabric.m_vGas[i].nextNodeValue/(fabric.m_porosity*fabric.m_meanFiberRadius);//revise


            if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
            {
                fabric.m_volumetricHeatCapacity[i] +=liquid.m_density*liquid.m_sHeatCapacity*fabric.m_vLiquidWater[i].nextNodeValue;

                fabric.m_thermoConductivity[i] +=liquid.m_thermoConductivity*fabric.m_vLiquidWater[i].nextNodeValue;
                
                /*DL*/
                fabric.m_diffusionCoeLiqWater[i]=3.0*liquid.m_surfaceTension
                                                  *Math.cos(fabric.m_meanFiberContactAngle*3.14159/180.0)
                                                  *fabric.m_effectivePoreRadius
                                                  *Math.pow(Math.sin(fabric.m_averageCapillaryAngle*3.14159/180.0),2)
                                                  *fabric.m_vLiquidWater[i].nextNodeValue
                                                  *liquid.m_density
                                                  /(40.0*fabric.m_porosity*liquid.m_dynamicViscosity);

            }

            if(fabric.m_modelFlag.compareTo(ModelType.AddNoLocal)>=0)
            {
                fabric.m_thermoConductivityGas[i]= gas.m_thermoConductivityGas * fabric.m_vGas[i].nextNodeValue ;
                fabric.m_volumetricHeatCapacity[i] -= gas.m_density * gas.m_sHeatCapacity *fabric.m_vGas[i].nextNodeValue;
                fabric.m_thermoConductivity[i] -= gas.m_thermoConductivityGas*fabric.m_vGas[i].nextNodeValue;

            }

            fabric.m_cWaterVapor[i].preNodeValue = fabric.m_cWaterVapor[i].nextNodeValue;

            fabric.m_tFabric[i].preNodeValue =fabric.m_tFabric[i].nextNodeValue;

            fabric.m_vGas[i].preNodeValue= fabric.m_vGas[i].nextNodeValue;

            if(fabric.m_modelFlag.compareTo(ModelType.AddLiquid)>=0)
            {
                fabric.m_vLiquidWater[i].preNodeValue = fabric.m_vLiquidWater[i].nextNodeValue;

            }

            if(fabric.m_modelFlag.compareTo(ModelType.AddPressure)>=0)
            {
                 fabric.m_pressureGas[i].preNodeValue = fabric.m_pressureGas[i].nextNodeValue;

            }

            if(fabric.m_modelFlag.compareTo(ModelType.AddVirus)>=0)
            {
                 fabric.m_cVirusInLiqWater[i].preNodeValue=fabric.m_cVirusInLiqWater[i].nextNodeValue;
                 fabric.m_vVirus[i].preNodeValue = fabric.m_vVirus[i].nextNodeValue;
            }

            if(fabric.m_modelFlag.compareTo(ModelType.AddNoLocal)>=0)
            {
                 fabric.m_tGas[i].preNodeValue = fabric.m_tGas[i].nextNodeValue;
                 //fabric.m_thermoConductivityGas[i] = fabric.m_thermoConductivityGas[i].nextNodeValue;
            }
            if(fabric.m_sourceItem.PCM)
            {
                 fabric.m_radiusInterfacePCM[i].preNodeValue=fabric.m_radiusInterfacePCM[i].nextNodeValue;
            }

        }// end for i
    };
    
    void SolveEquations() {
    	TMathPro.GaussSolver(m_matrixLeft,m_matrixRight);
    };
    
    void ClearMatrix() {
    	for(int i=0;i<m_matrixLeft.length;i++)
    	{
    		for(int j=0;j<m_matrixRight.length;j++)
    		{
    			m_matrixLeft[i][j]=0;
    		}
    		m_matrixRight[i]=0;
    	}
    };
};
